# -*- coding: utf-8 -*-

"""
@Datetime: 2019/4/19
@Author: Zhang Yafei
"""
from io import StringIO
from io import open

from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfinterp import PDFResourceManager, process_pdf


def readPDF(pdffile):
    rsrcmgr = PDFResourceManager()
    retstr = StringIO()
    laparams = LAParams()
    device = TextConverter(rsrcmgr, retstr, laparams=laparams)
    process_pdf(rsrcmgr, device, pdffile)
    device.close()
    content = retstr.getvalue()
    retstr.close()
    # strs = str(content).split("\n")
    # title = strs[2] + strs[3]
    return str(content)


pdffile = open('1.pdf', "rb")
text = readPDF(pdffile)
print(text)
pdffile.close()
